﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Markup;

using Aliphant.Interfaces;
using Aliphant.IoC;
using Aliphant.Script;

namespace Aliphant.Widget.JS.Utility
{
    public static class PageHelper
    {

        /// <summary>
        /// 加载Xaml页面
        /// </summary>
        /// <param name="filePath">页面路径</param>
        /// <returns></returns>
        public static object? LoadContentXaml(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return null;
            }

            string strXaml = File.ReadAllText(filePath);
            var fe = XamlReader.Parse(strXaml);
            
            return fe;
        }

        /// <summary>
        /// 加载JS脚本
        /// </summary>
        /// <param name="page">页面对象</param>
        /// <param name="filePath">脚本路径</param>
        public async static Task LoadJavaScript(object page, string filePath)
        {
            var manager = IoCServer.Container.Resolve<IScriptManager>();
            //var manager = new ScriptManager();
            await manager.ExecuteAsync(filePath, page, new string[] { "Aliphant.UI.Forms" });
        }
    }
}
